define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jingli/index' + location.search,
                    add_url: 'jingli/add',
                    edit_url: 'jingli/edit',
                    // del_url: 'jingli/del',
                    multi_url: 'jingli/multi',
                    import_url: 'jingli/import',
                    table: 'jingli',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'bigjingli.name', title: __('大区经理名称'), operate: false},
                        // {field: 'bigjingli_id', title: __('Bigjingli_id')},
                        {field: 'quyuname', title: __('Quyuname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'huikuan', title: __('Huikuan'), operate: 'LIKE'},
                        {field: 'storenum', title: __('Storenum')},
                        {field: 'c_num', title: __('C_num')},
                        {field: 'id', title: __('合伙人'), formatter: Controller.api.formatter.id,operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
                showExport: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['id'];
                    // var store_id = row['store_id'];
                    
                    url = "dailishang?jingli_id=" + ids;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容

                    return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("查看代理商", value) + '">' + '查看代理商' + '</a>';
                }
            }
        }
    };
    return Controller;
});